#include "World.h"

void CWorld::PushObject(CEntity * ent)
{
	if(ent != nullptr)
	{
		mObjects.insert(std::pair<unsigned int, CEntity*>(lastID++,ent));
		quadtree.PushObject(ent);
		ent->ID = lastID-1;	
	}
}

int CWorld::DeleteObject(CEntity * ent)
{
	if(ent != nullptr)
	{
		std::unordered_map<unsigned int, CEntity*>::iterator it = mObjects.find(ent->ID);
		return quadtree.deleteObject(ent);
		delete ent;
	}
	return false;
}

void CWorld::DrawObjects(sf::Rect<float> viewRect, sf::RenderWindow &window)
{
	quadtree.drawObjects(viewRect, window);
}

void  CWorld::getListOfObjects(sf::Rect<float> collRect, std::vector<CEntity*> &list)	{

}

void CWorld::Update()
{
	CEntity * obj = (*mObjects.find(lastID-1)).second;
	obj->move(0.1f,0.0f);
	quadtree.updateObject(obj);
}

CEntity * CWorld::getObjectByID(unsigned int ID)	{
	return nullptr;
}
CWorld::CWorld() : lastID(0)
{

}

CWorld::~CWorld()
{

}